function DrawSWTopo(swName) {
    canvas = document.getElementById('topo_canvas');
    // canvas.height = window.innerHeight * 0.895;
    // canvas.width = window.innerWidth * 0.98;

    canvas.height = 650;
    canvas.width = 900;

    scene = new JTopo.Scene();
    stage = new JTopo.Stage(canvas);
    stage.mode = 'drag';

    jsonStr = '';
    // bandWidthList = Array[11];
    // bandWidthList[1] = '255,0,255';
    // bandWidthList[10] = '255,0,255';
    var bandWidth = 0;
    $.ajax({
        url: '/getSWUplinkByName?sw_name=' + swName,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            var swInfo = '{' +
                '"elementType": "node",' +
                '"x": 450,' +
                '"y": 250,' +
                '"id": 112500,' +
                '"width": 80,' +
                '"heith": 160,' +
                '"Image": "SW.jpg",' +
                '"text": "' + swName + '",' +
                '"textPosition": "Middle_Left",' +
                '"level": 2' +
                '}'
            jsonStr = swInfo;
            for (var i = 0; i < data.length; i++) {
                if (data[i]['device_type'] == 'SR') {
                    var srInfo = '{' +
                        '"elementType": "node",' +
                        '"x": 301,' +
                        '"y": 50,' +
                        '"id": 15050,' +
                        '"width": 80,' +
                        '"heith": 160,' +
                        '"Image": "SR.jpg",' +
                        '"text": "' + data[i]['device_name'] + '",' +
                        '"textPosition": "Top_Center",' +
                        '"level": 1' +
                        '}'
                    jsonStr += ',' + srInfo;
                    if (data[i]['bandWidth'] == '1') {
                        bandWidth = 2;
                    } else {
                        bandWidth = 4;
                    }
                    for (var n = 0; n < data[i]['countCircuit']; n++) {
                        var circuitInfo = '{' +
                            '"elementType": "link",' +
                            '"nodeAid": 15050,' +
                            '"nodeZid": 112500,' +
                            '"text": "' + data[i]['max_flow'] + '",' +
                            '"fontColor": "255,0,255",' +
                            '"lineWidth": ' + bandWidth + ',' +
                            '}'
                        jsonStr += ',' + circuitInfo;
                    }
                } else if (data[i]['device_type'] == 'MSE') {
                    var srInfo = '{' +
                        '"elementType": "node",' +
                        '"x": 301,' +
                        '"y": 50,' +
                        '"id": 15050,' +
                        '"width": 80,' +
                        '"heith": 160,' +
                        '"Image": "MSE.jpg",' +
                        '"text": "' + data[i]['device_name'] + '",' +
                        '"textPosition": "Top_Center",' +
                        '"level": 1' +
                        '}'
                    jsonStr += ',' + srInfo;
                    if (data[i]['bandWidth'] == '1') {
                        bandWidth = 2;
                    } else {
                        bandWidth = 4;
                    }
                    for (var n = 0; n < data[i]['countCircuit']; n++) {
                        var circuitInfo = '{' +
                            '"elementType": "link",' +
                            '"nodeAid": 15050,' +
                            '"nodeZid": 112500,' +
                            '"text": "' + data[i]['max_flow'] + '",' +
                            '"fontColor": "255,0,255",' +
                            '"lineWidth": ' + bandWidth + ',' +
                            '}'
                        jsonStr += ',' + circuitInfo;
                    }
                } else if (data[i]['device_type'] == 'BAS') {
                    var bsInfo = '{' +
                        '"elementType": "node",' +
                        '"x": 600,' +
                        '"y": 50,' +
                        '"id": 30000,' +
                        '"width": 80,' +
                        '"heith": 160,' +
                        '"Image": "BS.jpg",' +
                        '"text": "' + data[i]['device_name'] + '",' +
                        '"textPosition": "Top_Center",' +
                        '"level": 1' +
                        '}';
                    jsonStr += ',' + bsInfo;
                    if (data[i]['bandWidth'] == '1') {
                        bandWidth = 2;
                    } else {
                        bandWidth = 4;
                    }
                    for (var n = 0; n < data[i]['countCircuit']; n++) {
                        var circuitInfo = '{' +
                            '"elementType": "link",' +
                            '"nodeAid": 30000,' +
                            '"nodeZid": 112500,' +
                            '"text": "' + data[i]['max_flow'] + '",' +
                            '"fontColor": "255,0,255",' +
                            '"lineWidth": ' + bandWidth + ',' +
                            '}'
                        jsonStr += ',' + circuitInfo;
                    }
                    // jsonStr += ','+bsInfo;
                }
            }
        }
    });
    var locationXList = [450, 200, 700, 100, 800, 100, 800, 100, 800, 100, 800];
    var locationYList = [550, 550, 550, 450, 450, 350, 350, 250, 250, 150, 150];
    var locationTextYList = [600, 600, 600, 500, 500, 400, 400, 300, 300, 200, 200];
    // var locationTextYList=[550,550,550,450,450,350,350,250,250];


    // var locationYList=[]
    $.ajax({
        url: '/getOltBySWName?sw_name=' + swName,
        dataType: 'JSON',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                var oltInfo = '{' +
                    '"elementType": "node",' +
                    '"x": ' + locationXList[i] + ',' +
                    '"y": ' + locationYList[i] + ',' +
                    '"id": ' + locationXList[i] * locationYList[i] + ',' +
                    '"width": 80,' +
                    '"heith": 160,' +
                    '"Image": "OLT.jpg",' +
                    '"text": "' + data[i]['olt_name'] + '",' +
                    '"textPosition": "Bottom_Center",' +
                    '"level": 3' +
                    '}';
                jsonStr += ',' + oltInfo;

                var userInfo = '{' +
                    '"elementType": "node",' +
                    '"x": ' + locationXList[i] + ',' +
                    '"y": ' + locationTextYList[i] + ',' +
                    '"id": ' + locationXList[i] * locationTextYList[i] + ',' +
                    '"width": 80,' +
                    '"heith": 160,' +
                    '"Image": "TEXT",' +
                    '"text": "活跃宽带用户:' + data[i]['actUser'] + '",' +
                    '"textPosition": "Bottom_Center",' +
                    '"level": 3' +
                    '}';
                jsonStr += ',' + userInfo;
                if (data[i]['countCircuit'] % 10 == 0) {
                    for (var n = 0; n < (data[i]['countCircuit'] / 10); n++) {
                        var circuitInfo = '{' +
                            '"elementType": "link",' +
                            '"nodeAid": 112500,' +
                            '"nodeZid": ' + locationXList[i] * locationYList[i] + ',' +
                            '"text": "' + data[i]['maxFlow'] + '",' +
                            '"fontColor": "255,0,255",' +
                            '"lineWidth": 4' +
                            '}';
                        jsonStr += ',' + circuitInfo;
                    }

                }else{
                    for (var n = 0; n < data[i]['countCircuit'] ; n++) {
                        var circuitInfo = '{' +
                            '"elementType": "link",' +
                            '"nodeAid": 112500,' +
                            '"nodeZid": ' + locationXList[i] * locationYList[i] + ',' +
                            '"text": "' + data[i]['maxFlow'] + '",' +
                            '"fontColor": "255,0,255",' +
                            '"lineWidth": 2 ' +
                            '}'
                        jsonStr += ',' + circuitInfo;
                    }
                }


            }
        }
    });
    jsonStr = '[' + jsonStr + ']';

    var jsonObj = eval("(" + jsonStr + ")");
    jsonObj.forEach(function (a) {
        if (a.elementType == "node") {
            if (a.Image == 'TEXT') {
                AddTextNode(a.x, a.y, a.text, scene)
            } else {
                AddNode(a.x, a.y, a.text, a.Image, a.textPosition, a.level);
            }

        } else if (a.elementType == "link") {
            var nodeA = scene.findElements(function (e) {
                return e.id == a.nodeAid;
            });
            var nodeZ = scene.findElements(function (e) {
                return e.id == a.nodeZid;
            });
            if (nodeA[0] && nodeZ[0]) {
                Addlink(nodeA[0], nodeZ[0], a.text, a.fontColor, a.lineWidth);
            }
        }
    });

    stage.add(scene);

    function AddNode(x, y, str, img, textPosition, level) {
        var node = new JTopo.Node(str);
        node.serializedProperties.push('id');
        node.serializedProperties.push('level');
        node.setLocation(x, y);
        node.Image = '';
        node.id = x * y;
        node.level = level;
        if (null != img) {
            node.setImage('./img/' + img, false);
            node.Image = img;
        }
        node.textPosition = textPosition;
        node.fontColor = '255,255,255';
        node.font = '16px Consolas'
        // node.setSize(60,60);
        scene.add(node);
        return node;
    }

    function Addlink(node1, node2, str, color, lineWidth) {
        var link = new JTopo.Link(node1, node2, str);
        link.lineWidth = lineWidth;//线宽
        link.bundleOffset = 60;
        link.bundleGap = 25;
        link.font = "16px Consolas";
        link.textOffsetY = 3;
        // link.fontColor = color || '0, 200, 255';
        // link.strokeColor = color || '0, 200, 255';
        link.fontColor = '255,255,255';
        link.strokeColor = '255, 255, 255';
        scene.add(link);
    }

    function AddTextNode(x, y, str, scene) {
        var node = new JTopo.Node(str);
        node.setLocation(x, y);
        node.serializedProperties.push('id');
        node.id = x + y;
        // node.fillColor = '255,255,255';
        node.textPosition = 'Bottom_Center';
        node.fontColor = '255,255,255';
        node.setSize(1, 1);
        node.dragable = false;
        node.showSelected = false;
        node.selected = false;
        scene.add(node);
    }

}
